import type { SideMenu } from "@/types/public";
import { create } from "zustand";
import { devtools } from "zustand/middleware";

interface MenuState {
    isCollapsed: boolean;
    selectedKeys: string; // 菜单选中值
    openKeys: string[]; // 菜单展开项
    menuList: SideMenu[]; // 菜单列表数据
    toggleCollapsed: (isCollapsed: boolean) => void;
    setSelectedKeys: (selectedKeys: string) => void;
    setOpenKeys: (openKeys: string[]) => void;
    setMenuList: (menuList: SideMenu[]) => void;
}

export const useMenuStore = create<MenuState>()(
    devtools(
        (set) => ({
            isCollapsed: false,
            selectedKeys: "", // 菜单选中值
            openKeys: ["system"], // 菜单展开项
            menuList: [], // 菜单列表数据
            toggleCollapsed: (isCollapsed: boolean) => set({ isCollapsed }),
            setSelectedKeys: (selectedKeys: string) => set({ selectedKeys }),
            setOpenKeys: (openKeys: string[]) => set({ openKeys }),
            setMenuList: (menuList: SideMenu[]) => set({ menuList }),
        }),
        {
            name: "menuStore",
        }
    )
);
